package com.nml.sensors;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class SensorEntityManager 
{
	private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("DatabaseConnector");
	
	public static void saveTransmission(Transmission sensorReading)
	{
		EntityManager em = emf.createEntityManager();
		
		em.getTransaction().begin();

		em.persist(sensorReading);
		
		em.getTransaction().commit();
		
		em.close();
	}
	
	public static void main(String[] args)
	{
		/*SensorReading sensorReading = new SensorReading();
		sensorReading.setCol2("Jimmy");
		sensorReading.setCol3(new BigDecimal(120.0));
		sensorReading.setCol4("Nail");
		sensorReading.setCol5(new Date());
		
		saveSensorReading(sensorReading);*/
		
		
		
		getTransmissions();
	}
	
	public static List<Transmission> getTransmissions()
	{
		
		EntityManager em = emf.createEntityManager();
		
		em.getTransaction().begin();

		Query q = em.createQuery("select TRANSMISSION from Transmission TRANSMISSION");
		List<Transmission> transmissions = q.getResultList();
		
		em.getTransaction().commit();
		
		em.close();
		
		return transmissions;
	}
}